import java.util.Arrays;

public class ArrayOperations {
    public static void main(String[] args) {
        int[] arr = {5, 2, 8, 1, 9};
        
        // 数组排序
        Arrays.sort(arr);
        System.out.println("排序后: " + Arrays.toString(arr));
        
        // 数组复制
        int[] copyArr = Arrays.copyOf(arr, arr.length);
        System.out.println("复制数组: " + Arrays.toString(copyArr));
        
        // 查找元素
        int index = Arrays.binarySearch(arr, 8);
        System.out.println("元素8的索引: " + index);
        
        // 数组比较
        int[] arr1 = {1, 2, 3};
        int[] arr2 = {1, 2, 3};
        System.out.println("数组是否相等: " + Arrays.equals(arr1, arr2));
        
        // 计算数组元素和
        int sum = 0;
        for (int num : arr) {
            sum += num;
        }
        System.out.println("数组元素和: " + sum);
        
        // 查找最大值和最小值
        int max = arr[0];
        int min = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] > max) max = arr[i];
            if (arr[i] < min) min = arr[i];
        }
        System.out.println("最大值: " + max + ", 最小值: " + min);
    }
}
